package com.langll.ai.tool;

import org.springframework.ai.chat.model.ToolContext;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.context.i18n.LocaleContextHolder;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 获取系统当前时间
 */
public class DateTimeTools {

    @Tool(description = "获取当前时间")
    public String getCurrentDateTime(){
        System.out.println("getCurrentDateTime ");
        return LocalDateTime.now().atZone(LocaleContextHolder.getTimeZone().toZoneId()).toString();
    }

    @Tool(description = "用户设置闹钟")
    void setAlarm(@ToolParam(description = "Time in ISO-8601 format")String time) {
        System.out.println("Alarm  time " + time);
        LocalDateTime alarmTime = LocalDateTime.parse(time, DateTimeFormatter.ISO_DATE_TIME);
        System.out.println("Alarm set for " + alarmTime);
    }

    @Tool(description = "更新客户信息")
    void updateCustomerInfo(Long id, String name, @ToolParam(required = false) String email) {
        System.out.println("Updated info for customer with id: " + id);
        System.out.println("Updated info for customer with name: " + name);
        System.out.println("Updated info for customer with email: " + email);
    }

    @Tool(description = "检索客户信息", resultConverter = CustomToolCallResultConverter.class, returnDirect = true)
    Customer getCustomerInfo(Long id, ToolContext toolContext) {
        System.out.println("id:" + id);
        Customer customer = new Customer();
        customer.setId(id);
        customer.setName("lang");
        customer.setEmail("lang@lenovo.com");
        String tenantId = toolContext.getContext().get("tenantId").toString();
        System.out.println("tenantId:" + tenantId);
        return customer;
    }
}
